package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.po.Coupon;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-29
 */
@Api(tags = "优惠卷接口")
@Slf4j
@RestController
@RequestMapping("/coupons")
@RequiredArgsConstructor
public class CouponController {

    private final ICouponService couponService;
    private final IUserCouponService ucService;

    /**
     * 优惠卷列表
     */
    @ApiOperation("展示优惠卷列表")
    @GetMapping("/list")
    public List<CouponVO> list() {
        log.info("优惠卷列表");
        return ucService.listVO();
    }

    /**
     * 发放优惠卷
     * @param dto
     * @return
     */
    @ApiOperation("发放优惠卷接口")
    @PutMapping("/{id}/issue")
    public void issueCoupon(@RequestBody @Valid CouponIssueFormDTO dto) {
        log.info("发放优惠卷");
        couponService.issueCoupon(dto);
    }

    /**
     * 分页查询优惠券接口
     */
    @ApiOperation("分页查询优惠券")
    @GetMapping("/page")
    public PageDTO<CouponPageVO> pageQuery(CouponQuery couponQuery) {
        log.info("分页查询优惠券接口");
        return couponService.pageQuery(couponQuery);
    }

    /**
     * 新增优惠卷接口
     * @param couponFormDTO
     */
    @ApiOperation("新增优惠券")
    @PostMapping
    public void addCoupon(@RequestBody CouponFormDTO couponFormDTO) {
        log.info("新增优惠券");
        couponService.addCoupon(couponFormDTO);
    }

    /**
     * 根据id查询优惠卷
     * @param id
     */
    @ApiOperation("根据id查询优惠卷")
    @GetMapping("/{id}")
    public CouponDetailVO getDetailById(@PathVariable Long id) {
        return couponService.getDetailById(id);
    }

    /**
     * 更新优惠卷信息
     * @param couponFormDTO
     */
    @ApiOperation("更新优惠卷信息")
    @PutMapping("/{id}")
    public void updateDetailById(@RequestBody CouponFormDTO couponFormDTO) {
        log.info("更新优惠券");
        couponService.updateDetailById(couponFormDTO);
    }

    /**
     * 删除优惠卷
     */
    @ApiOperation("删除优惠卷")
    @DeleteMapping("/{id}")
    public void deleteCouponById(@PathVariable Long id) {
        log.info("删除优惠券");
        couponService.removeById(id);
    }
}
